<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/22
 * Time: 10:10
 */

namespace app\modules\bridge\controller;

use app\modules\bridge\HelloWorldService;
use app\modules\bridge\HtmlFormatter;
use app\modules\bridge\PlainTextFormatter;
use yii\web\Controller;

class DefaultController extends Controller
{
    /**
     * 桥梁模式示例
     * 将抽象与实现分离，这样两者可以独立地改变
     *
     * @date   2018/11/22
     * @author edmmss
     * @return bool
     */
    public function actionIndex()
    {
        $htmlFormatter = new HtmlFormatter();
        $plainTextFormatter = new PlainTextFormatter();

        $helloWorld = new HelloWorldService($htmlFormatter);
        $string = $helloWorld->get();
        var_dump($string);

        $helloWorld = new HelloWorldService($plainTextFormatter);
        $string = $helloWorld->get();
        var_dump($string);

        return true;
    }
}